package xyz.jcat.generator.mybatis;

import org.beetl.core.Configuration;
import org.beetl.core.GroupTemplate;
import org.beetl.core.Template;
import org.beetl.core.resource.ClasspathResourceLoader;

import java.io.IOException;
import java.util.Map;

/**
 * beetl模板工具类
 *
 * @author yueyue
 * @Time 2017-05-18 16:02
 */
public class BeetlUtils {

    public static String getMsg(String basePath, String templateName, Map<String, Object> datas) throws IOException {
        ClasspathResourceLoader resourceLoader = new ClasspathResourceLoader(basePath);
        Configuration cfg = Configuration.defaultConfiguration();
        GroupTemplate gt = new GroupTemplate(resourceLoader, cfg);
        Template t = gt.getTemplate(templateName);
        t.binding(datas);
        String str = t.render();
        return str;
    }

}
